import { useDetail, useList } from "@/hooks";
import { getUserInfoUrl } from "@/command/apiTool";
import { getAction, postAction } from "@/command/netTool";
import { reactive, ref, watch } from "vue";
import * as vant from "vant";
const { showFailToast, showSuccessToast } = vant;
import { useRouter } from "vue-router";
export const useRequest = () => {
  const router = useRouter();
  const form = reactive({ path: "", id: "", name: "", content: "" });
  watch(form, (e) => {
    console.log(22222, e, form);
    getFarmProductInfo({
      id: e.id,
    });
  });
  const confirm = (params: any) => {
    console.log("eee", params);
    postAction(
      "/H5/skill/product/small/seedApply",
      { ...params },
      { isResolve: true }
    ).then((e) => {
      // showSuccessToast(e.msg)
    });
  };
  const getFarmProductInfo = (params: any) => {
    console.log("eee", params);
    getAction("/api/H5/util/getAgriculturalDetail", { ...params }).then((e) => {
      // showSuccessToast(e.msg)
      form.path = e.path;
      form.name = e.name;
      form.content = e.content;
    });
  };
  const [productList] = useDetail("/api/H5/util/getAgriculturalType", [], {
    // callBack: (data: any[]) => {
    //   return data.map((e) => ({ label: e.name, value: e.id }));
    // },
  });
  return {
    form,
    confirm,
    productList,
    getFarmProductInfo,
  };
};
